package com.ljsw.activity;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.graphics.Color;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.google.gson.Gson;
import com.ljsw.adapter.PKReconcilAdapter;
import com.ljsw.application.App;
import com.ljsw.entity.PKReonciliationEntity;
import com.ljsw.entity.PKreconciliationcheckpackge.TailZerotoEntity;
import com.ljsw.entity.QuanbieXinxi;
import com.ljsw.entity.gpk.PKInfoEntity;
import com.ljsw.entity.pkentity.ListMoney;
import com.ljsw.entity.pkentity.PKNotCompleteInfoEntity;
import com.ljsw.entity.pkentity.Reconcil.ListEditionByMoneyId;
import com.ljsw.entity.pkentity.Reconcil.PKReconcolEntity;
import com.ljsw.server.UpServer;
import com.ljsw.util.HxbSpinner;
import com.ljsw.util.MySpinner;
import com.ljsw.util.NumFormat;
import com.ljsw.util.QunabeiSpinner;
import com.ljsw.util.ShowToastUtils;
import com.ljsw.util.Table;
import com.pkutils.TurnListviewHeight;

import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import static android.R.attr.digits;


/****
 * 未完成的对账页面
 */
public class PKReconciliationCheckActivity extends Activity implements View.OnClickListener {
    private static final String defaultOptions = "请选择";
    private TextView pkreconciliationuser, taskno;//  操作人,任务编号
    private static final String TAG = "PKListInfoActivity";
    private Button btnupdatareconcheck;
    private ListView pkreconchecklist;
    private PKReconcilAdapter PKReconcilAdapter;
    private List<PKReconcolEntity> PKNotCompleteList = new ArrayList<PKReconcolEntity>();
    private TextView PKreconciliationcheck;//  查库编号
    private List<Integer> ltCurrent_WD = new ArrayList<Integer>();
    private List<List<Integer>> ltCurrent_Order = new ArrayList<List<Integer>>();// 网点显示状态列表
    private TextView PKreconciliationcheckNO, PKRCMonetcout;
    ;;//  盘库单号
    private List<String> stringList = new ArrayList<String>();//标牌集合

    private Handler handler;
    private List<PKInfoEntity> strlist1 = new ArrayList();
    private List<PKNotCompleteInfoEntity> listinfoentitylist = new ArrayList<PKNotCompleteInfoEntity>();//内层盘库明细实体
    private List<PKNotCompleteInfoEntity> listinfoentitylist2 = new ArrayList<PKNotCompleteInfoEntity>();//内层盘库明细实体
    private List<String> cansunlist = new ArrayList<String>();//  残损值


    private String str_zhuangtai[];//  状态的集合
    private Map<String, Map<String, String>> mapbanbieid = new HashMap<String, Map<String, String>>(); // 存储版别
    private Map<String, String> mapjiazhi = new HashMap<String, String>(); // 存储价值
    //    private List<TailPackgerEntityQuanbieXinxi> quanbieListxin = new ArrayList<TailPackgerEntityQuanbieXinxi>(); // 创建券别信息集合新版
//    private List<TailZerotoPackgerTianJiaXianJin> xianjinlisttinajia = new ArrayList<TailZerotoPackgerTianJiaXianJin>();
    private XianJinAdapter adapter;
    private String TaskNo;  //任务编号
    private String BPN0;//  标牌编号

    private QunabeiSpinner QunabeiSpinner;
    private HxbSpinner editionSpinner;

    private MySpinner spinner;
    private String juanbie;// 现金券别
    private String moneyBanbie;//版别
    private int isok = -1; // 现金的残损状态

    private List<TailZerotoEntity> TailZerotoEntitylist = new ArrayList<TailZerotoEntity>();// 数据源
    //    private List<TailPackgerEntityQuanbieXinxi> quanbieListxin = new ArrayList<TailPackgerEntityQuanbieXinxi>(); // 创建券别信息集合新版
    private List<QuanbieXinxi> quanbieList = new ArrayList<QuanbieXinxi>(); // 创建券别信息集合
    private List<QuanbieXinxi> banbielist = new ArrayList<QuanbieXinxi>(); // 创建券别信息集合
    private List<QuanbieXinxi> jiazhilist = new ArrayList<QuanbieXinxi>(); // 创建价值信息集合
    private String xianjingMsg;// 现金msg
    private Table[] table3 = new Table[10];// 声明一个数据
    //    private List<TailZerotoPackgerTianJiaXianJin> xianjinlisttinajia = new ArrayList<TailZerotoPackgerTianJiaXianJin>();
    private ArrayList<PKReonciliationEntity> checklist = new ArrayList<PKReonciliationEntity>();///  上一个页面传递值
    private List<ListMoney> listMoney = new ArrayList<ListMoney>();//  券别
    ///  版别
    private List<ListEditionByMoneyId> ListEditionByMoneyId = new ArrayList<ListEditionByMoneyId>();
    private List<String> ListEditionlist = new ArrayList<String>();

//    变量

    String coreInventoryAmount;
    String atmCashReplenishment;
    String transferFunds;
    String otherFunds;
    String strLibrary;
    private String BPNo;//
    private List<ListMoney> quanbieListxin1 = new ArrayList<ListMoney>(); // 创建券别信息集合新版
    private TextView tvBPNo;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_pk_reconciliationcheck);
        str_zhuangtai = new String[]{"完整券", "残损券"};
        Bundle bundle = getIntent().getExtras();
        ;
        checklist.clear();
        checklist = (ArrayList<PKReonciliationEntity>) bundle.getSerializable("gates");
        TaskNo = bundle.getString("TaskNo");

        BPNo = bundle.getString("BPNo");
        coreInventoryAmount = bundle.getString("coreInventoryAmount");
        atmCashReplenishment = bundle.getString("atmCashReplenishment");
        transferFunds = bundle.getString("transferFunds");
        otherFunds = bundle.getString("otherFunds");
        strLibrary = bundle.getString("strLibrary");


//        bundle.putString("coreInventoryAmount",coreInventoryAmount);
//        bundle.putString("atmCashReplenishment",atmCashReplenishment);
//        bundle.putString("transferFunds",transferFunds);
//        bundle.putString("otherFunds",otherFunds);
//        bundle.putString("strLibrary",strLibrary);
//        PKRCMonetcout.setText(coreInventoryAmount);//   设置库存金额
//        PKReconciliationzongjine.setText(scanTotalAmount);//  标牌扫描金额
//        PKRCA_ATMMoney.setText("" + atmCashReplenishment);// ATM金额
//        PKRCA_Diaojao.setText(transferFunds); // 调缴
//        pkreconcilitaother.setText(otherFunds); // 其他
//
//
//        PKreconciliationcheckNO.setText(strLibrary);//  库存编号


//        bundle.putString("TaskNo", TaskNo);
////        bundle.putParcelableArrayList("gates", (ArrayList<? extends Parcelable>) PKReonciliationEntitylist);
//        checklist.clear();
//        checklist = (List<PKReonciliationEntity>)getIntent().getSerializableExtra("par_key");
//        TaskNo = getIntent().getStringExtra("TaskNo");
//        BPN0 = getIntent().getStringExtra("");
        InitView();


        handler = new Handler() {
            @Override
            public void handleMessage(Message msg) {
                super.handleMessage(msg);
                switch (msg.what) {
                    case 0://登录成功后跳转 上门服务页面
//                        Toast.makeText(PKReconciliationCheckActivity.this, "添加成功", Toast.LENGTH_SHORT).show();
//                        str_zhuangtai = new String[]{"完整券", "残损券"};
////                        String quanbieXinxi = msg.obj.toString();
//                        String quanbieXinxi = netResult;
//                        System.out.println("获取的券别信息为：" + quanbieXinxi);
//                        Table[] table = Table.doParse(quanbieXinxi);
//                        for (int i = 0; i < TailZerotoEntitylist.size(); i++) {
//                            Map<String, String> val = new HashMap<String, String>();
//
//                            val.put("moneytype", TailZerotoEntitylist.get(i).getMONEYTYPE());
//                            val.put("meid", TailZerotoEntitylist.get(i).getMEID());
//                            val.put("parvalue", TailZerotoEntitylist.get(i).getPARVALUE());
//                            val.put("eidtion", TailZerotoEntitylist.get(i).getEDITION());
//                            val.put("lossvalue", TailZerotoEntitylist.get(i).getLOSSVALUE());
//                            mapbanbieid.put(TailZerotoEntitylist.get(i).getMEID(), val);
//
//                        }
//                        // 版别 banbielist
//                        for (Map.Entry<String, Map<String, String>> str : mapbanbieid.entrySet()) {
//                            TailPackgerEntityQuanbieXinxi tpexx = new TailPackgerEntityQuanbieXinxi();
//                            Map<String, String> val = str.getValue();
//                            tpexx.setCanshunJiazhi(val.get("lossvalue"));
//                            tpexx.setEDITION(val.get("eidtion"));
//                            tpexx.setQuanbieId(val.get("meid"));
//                            tpexx.setQuanbieName(val.get("moneytype"));
//                            tpexx.setQuanJiazhi(val.get("parvalue"));
//                            quanbieListxin.add(tpexx);
//
//                        }
//
//                        break;
                    case 1://登录超时
                        break;
                    case 2://用户不存在
                        Toast.makeText(PKReconciliationCheckActivity.this, " 提交信息失败" + netResult, Toast.LENGTH_SHORT).show();
                        break;
                    case 3://异常加载，无法访问服务器
//                        Toast.makeText(PKReconciliationCheckActivity.this, "" + "提交成功" + App.getApp().fanhuiMsg, Toast.LENGTH_SHORT).show();

                        View bottomViewup = View.inflate(PKReconciliationCheckActivity.this, R.layout.dialog_updata, null);//填充ListView布局
                        final AlertDialog parkIdsdialogup = new AlertDialog.Builder(PKReconciliationCheckActivity.this)
                                .setTitle("提交成功").setView(bottomViewup)//在这里把写好的这个listview的布局加载dialog中
//                                .setNeutralButton("取消", new DialogInterface.OnClickListener() {
//                                    @Override
//                                    public void onClick(DialogInterface dialog, int which) {
//                                        dialog.dismiss();
//                                    }
//                                })
                                .setNegativeButton("确定", new DialogInterface.OnClickListener() {

                                    @Override
                                    public void onClick(DialogInterface dialog, int which) {
                                        dialog.dismiss();
                                        PKReconciliationCheckActivity.this.finish();
                                    }
                                }).create();
                        parkIdsdialogup.show();
                        break;
                    case 4://账户长度是否正确符合要求 用户不存在
                        View bottomViewupfaiu = View.inflate(PKReconciliationCheckActivity.this, R.layout.dialog_updata, null);//填充ListView布局
                        final AlertDialog faiu = new AlertDialog.Builder(PKReconciliationCheckActivity.this)
                                .setTitle("提交失败" + netResult).setView(bottomViewupfaiu)//在这里把写好的这个listview的布局加载dialog中
                                .setNegativeButton("确定", new DialogInterface.OnClickListener() {

                                    @Override
                                    public void onClick(DialogInterface dialog, int which) {
                                        dialog.dismiss();

                                    }
                                }).create();
                        faiu.show();
                        break;
                    case 5://判断密码的长度密码错误
                        Toast.makeText(PKReconciliationCheckActivity.this, "请检查密码", Toast.LENGTH_SHORT).show();
                        break;

                    case 7://用户不正确
                        Toast.makeText(PKReconciliationCheckActivity.this, "请检查用户名", Toast.LENGTH_SHORT).show();
                        break;
                    case 8://用户不正确
                        Toast.makeText(PKReconciliationCheckActivity.this, "无返回结果", Toast.LENGTH_SHORT).show();
                        break;
                    case 9://用户不正确
                        Toast.makeText(PKReconciliationCheckActivity.this, "时间不对", Toast.LENGTH_SHORT).show();
                        break;
                    case 900:

                        Toast.makeText(PKReconciliationCheckActivity.this, " 获取券别信息失败!重试", Toast.LENGTH_SHORT).show();
                        break;
                    case 999:
                        Toast.makeText(PKReconciliationCheckActivity.this, " 获取券别信息失败!", Toast.LENGTH_SHORT).show();
                        break;
                    case 11:

                        Toast.makeText(PKReconciliationCheckActivity.this, " 获取券别信息失败!重试", Toast.LENGTH_SHORT).show();
                        break;
                    case 13:
                        View bottomView = View.inflate(PKReconciliationCheckActivity.this, R.layout.dialog_updata_succcess, null);//填充ListView布局
                        TextView textView = (TextView) bottomView.findViewById(R.id.dialog_success01);
                        final AlertDialog parkIdsdialog = new AlertDialog.Builder(PKReconciliationCheckActivity.this)
//                                .setTitle("提交信息")
                                .setView(bottomView)//在这里把写好的这个listview的布局加载dialog中
                                .setNeutralButton("取消", new DialogInterface.OnClickListener() {
                                    @Override
                                    public void onClick(DialogInterface dialog, int which) {
                                        dialog.dismiss();
                                    }
                                })
                                .setNegativeButton("确定", new DialogInterface.OnClickListener() {

                                    @Override
                                    public void onClick(DialogInterface dialog, int which) {
                                        dialog.dismiss();
                                    }
                                }).create();
                        parkIdsdialog.show();
                        break;
                    case 996:
                        String coupon = editionSpinner.getChooseText();
                        editionList.clear();
                        if (null != coupon) {
                            for (ListEditionByMoneyId item : ListEditionByMoneyId) {
                                if (moneyid.equals(item.getMoneyId())) {
                                    editionList.add(item.getEditIon());
                                }
                            }
                        }
                        QunabeiSpinner = new QunabeiSpinner
                                (PKReconciliationCheckActivity.this, tailzerotbanbie_spinner_layout, tailzeroto_banbie_spinner_text, editionList);
                        QunabeiSpinner.setSpinnerHeight(tailzerotbanbie_spinner_layout.getHeight() * 2);
                        QunabeiSpinner.showPopupWindow(tailzerotbanbie_spinner_layout);

                        break;
                    case 997:
                        showBigToast("获取券别版别基础信息失败请重试", 400);
                        View bottomView1 = View.inflate(PKReconciliationCheckActivity.this, R.layout.dialog_updata, null);//填充ListView布局
                        final AlertDialog parkIdsdialog1 = new AlertDialog.Builder(PKReconciliationCheckActivity.this)
                                .setTitle("").setView(bottomView1)//在这里把写好的这个listview的布局加载dialog中
//                                .setNeutralButton("取消", new DialogInterface.OnClickListener() {
//                                    @Override
//                                    public void onClick(DialogInterface dialog, int which) {
//                                        dialog.dismiss();
//                                    }
//                                })
                                .setNegativeButton("确定", new DialogInterface.OnClickListener() {

                                    @Override
                                    public void onClick(DialogInterface dialog, int which) {
                                        GETMoney();
                                        dialog.dismiss();
                                    }
                                }).create();
                        parkIdsdialog1.show();

                        break;
                    case 998:

                        for (int i = 0; i < listMoney.size(); i++) {

                            Map<String, String> val = new HashMap<String, String>();

                            val.put("moneytype", listMoney.get(i).getMoneytype());
                            val.put("moneyid", listMoney.get(i).getMoneyid());
                            val.put("parvalue", listMoney.get(i).getParvalue());
                            val.put("bagmoney", listMoney.get(i).getBagmoney());
//                            val.put("lossvalue", ListEditionByMoneyId.get(i).getLOSSVALUE());
                            mapbanbieid.put(listMoney.get(i).getMoneyid(), val);

                        }
                        // 版别 banbielist
                        for (Map.Entry<String, Map<String, String>> str : mapbanbieid.entrySet()) {
                            ListMoney tpexx = new ListMoney();
                            Map<String, String> val = str.getValue();
                            tpexx.setParvalue(val.get("parvalue"));
                            tpexx.setMoneyid(val.get("moneyid"));
                            tpexx.setBagmoney(val.get("bagmoney"));
                            tpexx.setMoneytype(val.get("moneytype"));
//                            tpexx.setQuanJiazhi(val.get("parvalue"));
                            quanbieListxin1.add(tpexx);

                        }
                        break;
                    case 10000://  刷新数据

                        adapter.notifyDataSetChanged();
                        break;
                    case 1000:

                        adapter.notifyDataSetChanged();
                        break;

                    case 888:
                        Toast.makeText(PKReconciliationCheckActivity.this, "没有获取版别信息", Toast.LENGTH_SHORT).show();

                        break;

                    case 889:
                        Toast.makeText(PKReconciliationCheckActivity.this, "删除数据成功", Toast.LENGTH_SHORT).show();

                        break;
                    default:
                        Toast.makeText(PKReconciliationCheckActivity.this, "请检查网络服务", Toast.LENGTH_SHORT).show();
                        break;
                }
            }
        };

    }


    @Override
    protected void onResume() {
        super.onResume();
        try {

//            MoneyInfo();//增加标牌明细 数据源代码/// 暂时不用

            GETMoney();//
            adapter = new XianJinAdapter(checklist, PKReconciliationCheckActivity.this);
            pkreconchecklist.setAdapter(adapter);
            setListViewHeight(pkreconchecklist);
            handler.sendEmptyMessage(10000);
        } catch (Exception e) {
            e.printStackTrace();
        }

    }

    /*
     *增加标牌明细 数据源代码
     */
    String ntResult = "";

    private void GETMoney() {
        new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    ntResult = UpServer.listMoney();
                    listMoney.clear();
                    if (null == ntResult || ntResult.equals("")) {
                        handler.sendEmptyMessage(999);
                    } else {
                        Gson gson = new Gson();
                        ListMoney[] lmcode = gson.fromJson(ntResult,
                                ListMoney[].class);
//                        for (int i = 0; i < lmcode.length; i++) {
                        listMoney = Arrays.asList(lmcode);
//                        }
                        handler.sendEmptyMessage(998);//  获取版别信息
                    }


                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }).start();


    }


    /***
     * 获取money id
     */
    public void listEditionByMoneyId() {
        new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    if (null == moneyid || moneyid.equals("")) {
                        for (int i = 0; i < quanbieListxin1.size(); i++) {
                            String coupon = "";
                            if (quanbieListxin1.get(i).getMoneytype().equals(editionSpinner.getChooseText())) {

                                moneyid = (quanbieListxin1.get(i).getMoneyid());
                            }
                        }

                    }

                    String netResult = UpServer.listEditionByMoneyId(moneyid);// 传去meid唯一标识
                    Log.e(TAG, "!!!!!!!!!!!1" + netResult);
                    if (null == netResult || netResult.equals("")) {
                        handler.sendEmptyMessage(997);
                    } else {
                        Gson gson = new Gson();
                        ListEditionByMoneyId[] lmcode = gson.fromJson(netResult,
                                ListEditionByMoneyId[].class);
                        for (int i = 0; i < lmcode.length; i++) {
                            ListEditionByMoneyId = Arrays.asList(lmcode);
                        }
                        handler.sendEmptyMessage(996);//  获取版别信息
                    }


                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }).start();

    }


    /*
     * 获取 新增加标牌明细 数据源代码
     * <p>
     * 所有的券别 版别  残损
     */
//    private void MoneyInfo() {
//        new Thread(new Runnable() {
//            public void run() {
//                listinfoentitylist.clear();
//
//                try {
//                    String netResult = UpServer.getMoneyInfoList();
//                    if (null == netResult || netResult.equals("")) {
//                    } else {
//
//                        handler.sendEmptyMessage(12);// 返回数据为空请重试
//                        Log.e(TAG, "---------------------------------" + netResult);
//                        Gson gson = new Gson();
//                        TailZerotoEntity[] mTailZerotoEntity = gson.fromJson(netResult, TailZerotoEntity[].class);
//                        for (int i = 0; i < mTailZerotoEntity.length; i++) {
//                            TailZerotoEntitylist = Arrays.asList(mTailZerotoEntity);
//                        }
//                        if (TailZerotoEntitylist != null && !TailZerotoEntitylist.equals("")) {
//                            handler.sendEmptyMessage(0);
//                        } else {
//                            handler.sendEmptyMessage(11);//  获取券别信息失败
//
//                        }
//
//                    }
//
//                    if (null == netResult || ("").equals(netResult)) {
//                        handler.sendEmptyMessage(3);
//                    } else {
//                        listinfoentitylist = JSONObject.parseArray(netResult, PKNotCompleteInfoEntity.class);
//
//                        handler.sendEmptyMessage(0);
//                    }

//                } catch (Exception e) {
//                    e.printStackTrace();
//                }
//            }
//        }).start();
//
//    }

    private EditText tailzeroet;
    private TextView tailzero_heji, taizero_spinner_text_zhuangtai, tailzeroto_banbie_spinner_text;
    private LinearLayout tailzerot_spinner_layout, taizero_spinner_layout_zhuangtai, tailzerotbanbie_spinner_layout;
    private TextView tailzero_spinner_text;//
    private TextView tailzero_xianjin_tianjia;
    private ImageView pkreconcheckblack;
    private Button pkreconcheck_update;


    // 组件

    private String str_tailzeroet;

    private void InitView() {
        pkreconcheck_update = (Button) findViewById(R.id.pkreconcheck_update);
        pkreconcheck_update.setOnClickListener(this);

        pkreconcheckblack = (ImageView) findViewById(R.id.pkreconcheckblack);//返回
        pkreconcheckblack.setOnClickListener(this);

        pkreconchecklist = (ListView) findViewById(R.id.tailzerotopackgeslistview);
        btnupdatareconcheck = (Button) findViewById(R.id.btnupdatareconcheck);/// 提交数据
        btnupdatareconcheck.setOnClickListener(this);
        tailzeroet = (EditText) findViewById(R.id.tailzeroet);/// 可以输入小数
        tailzeroet.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

                //如果.在起始位置,则起始位置自动补0
                if (s.toString().trim().substring(0).equals(".")) {
                    s = "0" + s;
                    tailzeroet.setText(s);
                    tailzeroet.setSelection(2);
                }

                //如果起始位置为0并且第二位跟的不是".",则无法后续输入
                if (s.toString().startsWith("0")
                        && s.toString().trim().length() > 1) {
                    if (!s.toString().substring(1, 2).equals(".")) {
                        tailzeroet.setText(s.subSequence(0, 1));
                        tailzeroet.setSelection(1);
                        return;
                    }
                }


            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {

                if (s.toString().contains(".")) {
                    if (s.length() - 1 - s.toString().indexOf(".") > digits) {
                        s = s.toString().subSequence(0,
                                s.toString().indexOf(".") + digits + 1);
                        tailzeroet.setText(s);
                        tailzeroet.setSelection(s.length()); //光标移到最后
                    }
                }
                //如果"."在起始位置,则起始位置自动补0
                if (s.toString().trim().substring(0).equals(".")) {
                    s = "0" + s;
                    if (s.length() > 2) {
                        Toast.makeText(PKReconciliationCheckActivity.this, "输入不正确", 400).show();
                        tailzeroet.setText("");
                        tailzeroet.setSelection(2);
                    } else {


                        tailzeroet.setText(s);
                        tailzeroet.setSelection(2);
                    }
                }

                //如果起始位置为0,且第二位跟的不是".",则无法后续输入
                if (s.toString().startsWith("0")
                        && s.toString().trim().length() > 1) {
                    if (!s.toString().substring(1, 2).equals(".")) {
                        tailzeroet.setText(s.subSequence(0, 1));
                        tailzeroet.setSelection(1);
                        return;
                    }
                }


//                --------------------------------
                if (s.toString().contains(".")) {
                    if (s.length() - 1 - s.toString().indexOf(".") > 2) {
                        s = s.toString().subSequence(0,
                                s.toString().indexOf(".") + 3);
                        tailzeroet.setText(s);
                        tailzeroet.setSelection(s.length());
                    }
                }
                if (s.toString().trim().substring(0).equals(".")) {
                    s = "0" + s;
                    tailzeroet.setText(s);
                    tailzeroet.setSelection(2);
                }

                if (s.toString().startsWith("0")
                        && s.toString().trim().length() > 1) {
                    if (!s.toString().substring(1, 2).equals(".")) {
                        tailzeroet.setText(s.subSequence(0, 1));
                        tailzeroet.setSelection(1);
                        return;
                    }
                }


            }

            @Override
            public void afterTextChanged(Editable s) {

            }
        });


        str_tailzeroet = tailzeroet.getText().toString();
        tailzero_heji = (TextView) findViewById(R.id.tailzero_heji);// /合计


        tailzerot_spinner_layout = (LinearLayout) findViewById(R.id.tailzeroto_spinner_layout);
        tailzerot_spinner_layout.setOnClickListener(this);
        tailzero_spinner_text = (TextView) findViewById(R.id.tailzeroto_spinner_text);
        tailzero_xianjin_tianjia = (Button) findViewById(R.id.tailzero_xianjin_tianjia);
        tailzero_xianjin_tianjia.setOnClickListener(this);

        taizero_spinner_layout_zhuangtai = (LinearLayout) findViewById(R.id.taizero_spinner_layout_zhuangtai);
        taizero_spinner_layout_zhuangtai.setOnClickListener(this);

        taizero_spinner_text_zhuangtai = (TextView) findViewById(R.id.taizero_spinner_text_zhuangtai);
        tailzero_heji = (TextView) findViewById(R.id.tailzero_heji);

        tailzerotbanbie_spinner_layout = (LinearLayout) findViewById(R.id.tailzerotbanbie_spinner_layout);
        tailzerotbanbie_spinner_layout.setOnClickListener(this);
        tailzeroto_banbie_spinner_text = (TextView) findViewById(R.id.tailzeroto_banbie_spinner_text);
//        tailzero_xianjin_tianjia = (Button) findViewById(R.id.tailzero_xianjin_tianjia);
//        tailzero_xianjin_tianjia.setOnClickListener(this);
        tvBPNo = (TextView) findViewById(R.id.BPNo);
        tvBPNo.setText(BPNo);
    }

    String result1 = "";
    String moneyid = "";
    List<String> editionList = new ArrayList<String>();

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.btnupdatareconcheck://  提交数据
                pkRECAUpdata();
                break;
            // 券别
            case R.id.tailzeroto_spinner_layout:
                List<String> couponList = new ArrayList<String>();
                for (ListMoney item : quanbieListxin1) {
                    String coupon = item.getMoneytype();
                    if (!couponList.contains(coupon)) {
                        couponList.add(coupon);
                    }
                }
                if (null == listMoney) {
                    handler.sendEmptyMessage(900);// 获取失败重试

                } else {
                    editionSpinner = new HxbSpinner(this, tailzerot_spinner_layout, tailzero_spinner_text, couponList);
                    editionSpinner.setSpinnerHeight(tailzerot_spinner_layout.getHeight() * 2);
                    editionSpinner.showPopupWindow(tailzerot_spinner_layout);
                    if (editionSpinner != null) {
                        if (tailzeroto_banbie_spinner_text != null)


                            result1 = tailzeroto_banbie_spinner_text.getText().toString();
                        tailzeroto_banbie_spinner_text.setText(defaultOptions);
                        result1 = editionSpinner.getChooseText();
                    }
//                     获取money id

                }

                result1 = editionSpinner.getChooseText();

                break;
            // 版别选择
            case R.id.tailzerotbanbie_spinner_layout:


                if (null == editionSpinner || editionSpinner.equals("")) {
                    showBigToast("请选版别", 100);
                } else {
                    String coupon = editionSpinner.getChooseText();
//
//                    //  获取meid  在下一层
//                    for (int i = 0; i < quanbieListxin1.size(); i++) {
//                        if (quanbieListxin1.get(i).getMoneytype().equals(coupon)) {
//
//                            moneyid = (quanbieListxin1.get(i).getMoneyid());
//                            if (moneyid.equals("") || moneyid == null) {
//                            } else {
//                                listEditionByMoneyId();
//                            }
//                        }
//                    }


                    //  获取meid  在下一层
                    for (int i = 0; i < quanbieListxin1.size(); i++) {
                        if (quanbieListxin1.get(i).getMoneytype().equals(coupon)) {

                            moneyid = (quanbieListxin1.get(i).getMoneyid());
                            if (moneyid.equals("") || moneyid == null) {
                            } else {
                                listEditionByMoneyId();
                            }


                        }
                    }
                    editionList.clear();
                    if (null != coupon) {
                        for (ListEditionByMoneyId item : ListEditionByMoneyId) {
                            if (moneyid.equals(item.getMoneyId())) {
                                editionList.add(item.getEditIon());
                            }
                        }
                    }

                    if (null == ListEditionByMoneyId) {
                        ShowToastUtils showToastUtils = new ShowToastUtils();
                        showToastUtils.showBigToast("请选择券别", 400);
                    }
                    QunabeiSpinner = new QunabeiSpinner
                            (this, tailzerotbanbie_spinner_layout, tailzeroto_banbie_spinner_text, editionList);
                    QunabeiSpinner.setSpinnerHeight(tailzerotbanbie_spinner_layout.getHeight() * 2);
                    QunabeiSpinner.showPopupWindow(tailzerotbanbie_spinner_layout);
                    QunabeiSpinner.dismiss();
                }
                break;

            case R.id.tailzero_xianjin_tianjia:
                if (null == editionSpinner || null == editionSpinner.getChooseText() || null == editionSpinner
                        || null == editionSpinner.getChooseText()) {
                    Log.d(TAG, "空的不让选！！！！！！！");
                    showBigToast("请先选择版别和券别数据", 400);
//                    hbt_tailzmakecard_btn.setEnabled(false);
//                    hbt_tailzmakecard_btn.setBackgroundResource(R.drawable.buttom_selector_bg);
                    return;
                } else {

                    addXianJin();
//                    hbt_tailzmakecard_btn.setEnabled(true);
//                    hbt_tailzmakecard_btn.setBackgroundResource(R.drawable.buttom_selector_bg);
                }
                break;

            case R.id.taizero_spinner_layout_zhuangtai:
                spinner = new MySpinner(this, taizero_spinner_layout_zhuangtai, taizero_spinner_text_zhuangtai);
                spinner.setSpinnerHeight(taizero_spinner_layout_zhuangtai.getHeight() * 2);
                spinner.setList(this, str_zhuangtai);
                spinner.showPopupWindow(taizero_spinner_layout_zhuangtai);
                spinner.setList(this, str_zhuangtai, 40);
                break;
            case R.id.pkreconcheckblack:
                PKReconciliationCheckActivity.this.finish();
                break;

            case R.id.pkreconcheck_update:
                GETMoney();//  获取券别版本信息
                break;
            default:
                break;
        }

    }

    /*
     * 提交标牌明细
     */
    String netResult = "";

    private void pkRECAUpdata() {
        new Thread(new Runnable() {
            public void run() {
//                String repertoryRental = "库存标牌总额";
//                String atmCashMoney = "ATM加钞款项";
//                String payment = "调缴款项";
//                String other = " 其他款项";

//                coreInventoryAmount = bundle.getString("coreInventoryAmount");
//                atmCashReplenishment = bundle.getString("atmCashReplenishment");
//                transferFunds = bundle.getString("transferFunds");
//                otherFunds = bundle.getString("otherFunds");
//                strLibrary = bundle.getString("strLibrary");
                String Userid = App.userZhanghao;
                String UserName = App.user.getName();
                JSONObject jsonObjectA = new JSONObject();
                JSONArray jsonArrayA = new JSONArray();
                jsonObjectA.put("zongmoney", coreInventoryAmount);
                jsonObjectA.put("repertoryId", strLibrary);
                jsonObjectA.put("atmoney", atmCashReplenishment);
                jsonObjectA.put("djmoney", transferFunds);
                jsonObjectA.put("qtmoney", otherFunds);
                jsonObjectA.put("scutcheonsNum", BPNo);
//                scutcheonsNum:标牌编号1,
//                        moneyId:券别编号,
//                        moneyType:券别名称,
//                        clbb:版别,
//                        clwc: 完残状态,
//                        cllr:录入金额
//-------------------------------------------
                //                model.setMONEY(xjcount);
//                model.setDAMAGEDSTATE(taizero_spinner_text_zhuangtai.getText().toString());
//                model.setEDITIONNUM(QunabeiSpinner.getChooseText());
//                model.setMONEYDETAIL(juanbie);
//                model.setMONEYNUM(moneyid);
//                model.setSCUTCHEONSNUM(BPNo);
                for (int i = 0; i < checklist.size(); i++) {
                    JSONObject jsonObject1 = new JSONObject();
                    jsonObject1.put("scutcheonsNum", BPNo);
                    jsonObject1.put("moneyId", checklist.get(i).getMONEYNUM());
                    jsonObject1.put("moneyType", checklist.get(i).getMONEYDETAIL());
                    jsonObject1.put("clbb", checklist.get(i).getEDITIONNUM());
                    jsonObject1.put("clwc", checklist.get(i).getDAMAGEDSTATE());
                    jsonObject1.put("cllr", checklist.get(i).getMONEY());
                    jsonArrayA.add(jsonObject1);
                }

                jsonObjectA.put("details", jsonArrayA);

                try {
                    Log.e(TAG, "---------------------------------");
                    netResult = UpServer.editInventoryMaintain(jsonObjectA + "", Userid, UserName);
                    Log.e(TAG, "------------------------结果：：：---------" + netResult);
                    if (("00").equals(netResult)) {
                        handler.sendEmptyMessage(3);//   提交成功
                    } else {
                        handler.sendEmptyMessage(4);///  提交失败
                    }
                } catch (NullPointerException e) {
                    e.printStackTrace();
                    handler.sendEmptyMessage(2);//查无此人信息
                } catch (NumberFormatException e) {
                    e.printStackTrace();
                    handler.sendEmptyMessage(2);//不是数字
                } catch (Exception e) {

                    e.printStackTrace();
                    Log.e("b", "异常" + e);
//                    Log.e("data报文加密失败！", e.getMessage());
                    handler.sendEmptyMessage(2);
                }
            }
        }).start();

}


    private String setstate;//  是否全损伤
    private String delete = "0";// 是否删除过

    class XianJinAdapter extends BaseAdapter {
        private List<PKReonciliationEntity> LockID;
        private Context mContext;

        public XianJinAdapter(List<PKReonciliationEntity> checklist, Context mContext) {
            super();
            this.LockID = LockID;
            this.mContext = mContext;
        }


        LayoutInflater lf = LayoutInflater.from(PKReconciliationCheckActivity.this);
        ViewHodler view;


        @Override
        public int getCount() {
            return checklist.size();
        }

        @Override
        public Object getItem(int arg0) {
            return checklist.get(arg0);
        }

        @Override
        public long getItemId(int arg0) {
            return arg0;
        }

        @Override
        public View getView(final int position, View arg1, ViewGroup arg2) {
            if (arg1 == null) {
                arg1 = lf.inflate(R.layout.adapter_tailzerot_packger_tianjia, null);
                view = new ViewHodler();
                view.banbie = (TextView) arg1.findViewById(R.id.tailzerotada_title_tv0);
                view.juanbie = (TextView) arg1.findViewById(R.id.tailzerotada_title_tv1);
                view.zhuangtai = (TextView) arg1.findViewById(R.id.tailzerotada_title_tv2);
                view.shuliang = (TextView) arg1.findViewById(R.id.tailzerotada_title_tv3);
                view.shanchu = (Button) arg1.findViewById(R.id.tailzerotada_title_button);
                arg1.setTag(view);
            } else {
                view = (ViewHodler) arg1.getTag();
            }
            PKReonciliationEntity iObj = checklist.get(position);
            view.banbie.setText(iObj.getMONEYDETAIL());// 券别
            view.juanbie.setText(iObj.getEDITIONNUM());
            view.zhuangtai.setText(iObj.getDAMAGEDSTATE());

            String state = iObj.getDAMAGEDSTATE();
            if (state.equals("0")) {
                view.zhuangtai.setText("全额");
                setstate = "2";
            } else if (state.equals("1")) {
                view.zhuangtai.setText("全损");
                setstate = "4";
//            } else if (state.equals("2")) {
//                view.zhuangtai.setText("半损");
//                setstate = "4";
            }
            // view.zhuangtai.setText(xianjinlist.get(position).getZhuangtai());
            view.shuliang.setText(checklist.get(position).getMONEY());
            view.shanchu.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View arg0) {
                    checklist.remove(position);
                    delete = "2"; // 现金被删除过
//                    Heji();
                    adapter.notifyDataSetChanged();
                    new TurnListviewHeight(pkreconchecklist);
                    handler.sendEmptyMessage(889);
                }
            });
            return arg1;
        }
    }

    public static class ViewHodler {
        TextView juanbie, zhuangtai, shuliang, banbie;
        Button shanchu;
    }


    /**
     * 合计
     */
    int heji_xianjin;

    public void Heji() {

        heji_xianjin = 0;
        if (checklist.size() != 0) {

            for (int i = 0; i < checklist.size(); i++) {
                int count = Integer.parseInt(checklist.get(i).getMONEY().trim());
//                double quanJiazhi = Double.parseDouble(checklist.get(i).getQuanJiazhi().trim());
//                double canshuJiazhi = Double.parseDouble(checklist.get(i).getCanshunJiazhi().trim());
//                int zhuangtai = Integer.parseInt(checklist.get(i).getDAMAGEDSTATE().trim());
//
//                switch (zhuangtai) {
//                    case 0: // 全额
                heji_xianjin += (double) (1 * count);
//                        break;
//                    case 1: // 全损
//                        heji_xianjin += (double) (quanJiazhi * count);
//                        break;
//                    case 2: // 半损
//                        heji_xianjin += (double) (canshuJiazhi * count);
//                        break;
//                }
            }
        }
        tailzero_heji.setText(new NumFormat().format(heji_xianjin + ""));
    }

    public void showBigToast(String info, int duration) {

        Toast toast = new Toast(PKReconciliationCheckActivity.this);
        toast.setGravity(Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM, 0, 50);
        TextView tv = new TextView(PKReconciliationCheckActivity.this);
        tv.setBackgroundResource(R.drawable.bg_toast);
        tv.setGravity(Gravity.CENTER);
        tv.setPadding(25, 5, 25, 5);
        tv.setTextColor(Color.WHITE);
        tv.setText(info);
        tv.setTextSize(30);
        toast.setView(tv);
        toast.setDuration(duration);
        toast.show();

    }


    /****
     * 添加现金
     */
    public void addXianJin() {
        String xjcount = tailzeroet.getText().toString();
if(null==xjcount||xjcount.equals("")){
    showBigToast("请输入现金", 500);
return;
}

        if(null==xjcount||xjcount.equals("")){
            showBigToast("请输入现金", 500);
            return;
        }
//        if (null == couopnSpinner.getChooseText()) {
//
//            showBigToast("请选择现金", 500);
//            return;
//        } else {
        juanbie = editionSpinner.getChooseText();
//        }

        if (null == juanbie || juanbie.equals(defaultOptions)) {
//            manager.getResultmsg().resultmsg(this, "请选择券别类型", false);
            showBigToast("请选择券别类型", 500);
            return;
        }
        moneyBanbie = QunabeiSpinner.getChooseText();
        if (null == moneyBanbie || moneyBanbie.equals("")) {
            showBigToast("请选择版别", 500);
//            manager.getResultmsg().resultmsg(this, "请选择版别", false);
            return;
        } else {

//            if (null == moneyversion || moneyversion.equals(defaultOptions)) {
////                manager.getResultmsg().resultmsg(this, "请选择版别", false);
//                showBigToast("请选择版别", 500);
//                return;
//            }
        }

        String zhuangtai = taizero_spinner_text_zhuangtai.getText().toString();
        if (TextUtils.isEmpty(zhuangtai) || zhuangtai.equals(defaultOptions)) {
//            manager.getResultmsg().resultmsg(this, "请选择状态", false);
            showBigToast("请选择状态", 500);
            return;

        }
        if (TextUtils.isEmpty(xjcount)) {
//            manager.getResultmsg().resultmsg(this, "请输入数量", false);
            showBigToast("请输入数量", 500);
            return;
        }
        // 将残损状态名称改为残损状态id
        if (!"".equals(zhuangtai) && null != zhuangtai) {
            if (zhuangtai.equals("完整券")) {
//                zhuangtai = "2";
//            } else if (zhuangtai.equals("半损券")) {
//                zhuangtai = "2";
            } else if (zhuangtai.equals("残基券")) {
//                zhuangtai = "4";
            }
        }
//        MONEYDETAIL":"纸100元（5套）","SCUTCHEONSNUM":"11","MONEY":"6000","DAMAGEDSTATE":"完整券","ID":"999b09f2c781413f9f9198226aa59d24","EDITIONNUM":"2015","MONEYNUM":"01"
//                *
//        PKReonciliationEntity model = new PKReonciliationEntity();
//        model.setMONEY(xjcount);
//        model.setDAMAGEDSTATE(taizero_spinner_text_zhuangtai.getText().toString());
//        model.setEDITIONNUM(QunabeiSpinner.getChooseText());
//        model.setMONEYDETAIL(juanbie);
//        model.setMoneyId(moneyid);
//拿到用户输入集合数据
        ListMoney choose = PKReconciliationCheckActivity.this.getTailPackgerEntityQuanbieXinxi(juanbie, moneyBanbie);

//        if (choose != null) {
//            System.out.println("现金集合开始添加-->" + zhuangtai);
//            ListMoney mode = this.chooseExists(choose.getMoneyid(),moneyBanbie,juanbie, zhuangtai);
//            PKReonciliationEntity model = new PKReonciliationEntity();
//            if (mode != null) {
//                model.setMONEY(String.valueOf(Integer.parseInt(xjcount) + Integer.parseInt(xjcount)* Integer.parseInt(mode.getBagmoney())));
//            } else {
//                model = new PKReonciliationEntity();
//                model.setMONEY(xjcount);//  数量
//                model.setEDITIONNUM(choose.getQuanbieId());
//                model.setCashbanbie(moneyversion);
//                model.setCount(xjcount);
//                model.setJuanbie(juanbie);
//                model.setQuanJiazhi(choose.getQuanJiazhi());
//                model.setZhuangtai(zhuangtai);


//                PKReonciliationEntity model = new PKReonciliationEntity();
//                model.setMONEY(xjcount);
//                model.setDAMAGEDSTATE(taizero_spinner_text_zhuangtai.getText().toString());
//                model.setEDITIONNUM(QunabeiSpinner.getChooseText());
//                model.setMONEYDETAIL(juanbie);
//                model.setMONEYNUM(moneyid);
//                mode.setMONEYNUM(BPNo);

//                checklist.add(model);


//
//            }
//        } else {
//            int listcount = Integer.parseInt(checklist.get(checklist.size()-1).getMONEY());
//            int xjshuliang = Integer.parseInt(xjcount);
//            int count = listcount + xjshuliang;
//            checklist.get(checklist.size()-1).setMONEY(count + "");
//            isok = -1;
//        }

        if (choose != null) {
            System.out.println("现金集合开始添加-->" + zhuangtai);
            PKReonciliationEntity model = this.chooseExists(choose.getMoneyid(), zhuangtai);
            if (model != null) {
//                BigDecimal b1 = new BigDecimal(Float.toString(Float.parseFloat(xjcount)) + "");
//                BigDecimal b2 = new BigDecimal(Float.toString(Float.parseFloat(model.getMONEY())) + "");
//                String s3 = b1.add(b2).doubleValue() + "";
//                String s1 = BigDecimal.valueOf(b1.add(b2).floatValue()) + "";
//                String s = BigDecimal.valueOf(b1.add(b2).floatValue()).stripTrailingZeros().toPlainString();//让bigdecimal不用科学计数法显示
//                Log.e(TAG, "!!!!!!!!!!!!!!!!!!!!!" + s3);
//                BigDecimal bg = new BigDecimal(s3);

                String strxjcount = new BigDecimal(xjcount.toString()).toString();
                String strtypet = new BigDecimal(model.getMONEY()).toString();

                BigDecimal b1 = new BigDecimal(Float.toString(Float.parseFloat(strxjcount)));
                BigDecimal b2 = new BigDecimal(Float.toString(Float.parseFloat(strtypet)));

                BigDecimal totalAmount = new BigDecimal(0);
                totalAmount = totalAmount.add(new BigDecimal(strxjcount.toString()));

                totalAmount = totalAmount.add(new BigDecimal(strtypet.toString()));

                String priceVal = new java.text.DecimalFormat("######0.00")
                        .format(totalAmount.setScale(2, BigDecimal.ROUND_UP).doubleValue());

                model.setMONEY(priceVal );


//                model.setMONEY(String.valueOf(Double.parseDouble(xjcount) + Double.parseDouble(model.getMONEY())));
            } else {
                model = new PKReonciliationEntity();
                model.setMONEY(xjcount);
                model.setDAMAGEDSTATE(taizero_spinner_text_zhuangtai.getText().toString());
                model.setEDITIONNUM(QunabeiSpinner.getChooseText());
                model.setMONEYDETAIL(juanbie);
                model.setMONEYNUM(moneyid);
                model.setSCUTCHEONSNUM(BPNo);
                checklist.add(model);
            }
        } else {
            Float listcount = Float.parseFloat(checklist.get(checklist.size() - 1).getMONEY());
            Float xjshuliang = Float.parseFloat(xjcount);
            Float count = listcount + xjshuliang;
//            xianjinlisttinajia.get(isok).setCount(count + "");
            Float res = count;
            if (res.toString().indexOf("E") > -1) {
                Double mun = Double.parseDouble(res.toString());
                String result = new DecimalFormat("0.00").format(mun);

            } else {
            }
            isok = -1;
        }


//        adapter.notifyDataSetChanged();
//        Heji();
        pkreconchecklist.setAdapter(adapter);
        new TurnListviewHeight(pkreconchecklist);
        handler.sendEmptyMessage(1000);
        System.out.println("现金集合的数量----->");
        for (int i = 0; i < checklist.size(); i++) {
            System.out
                    .println(checklist.get(i).getMONEYDETAIL() + "----->>" + checklist.get(i).getMONEY());
        }

    }

    /**
     * 根据券别、版别得到唯一的那一条记录
     *
     * @param juanbie,moneyBanbie
     * @return juanbie, moneyversion
     */

    private String GETADDMoneyid;
    String banbie = "";//  数据有变化    所以需要判断版别的类型   100  为例子    2005 -2   2015-1    2000 -3

    private ListMoney getTailPackgerEntityQuanbieXinxi(String juanbie, String moneyBanbie) {
        if ((null == juanbie || null == juanbie) || moneyBanbie.equals("") || moneyBanbie.equals("")) {

//            manager.getResultmsg().resultmsg(this, "请选择版别", false);
            showBigToast("请选择版别", 500);
        } else {
            if (juanbie.equals("")) {
                showBigToast("请选择" + juanbie, 100);
            }
//  寻找meid
            String GETADDMoneyVersion = "";
            ListEditionlist.clear();
            banbie = "";


            for (int i = 0; i < ListEditionByMoneyId.size(); i++) {
                if (ListEditionByMoneyId.get(i).getEditIon().equals(moneyBanbie)) {
                    GETADDMoneyid = ListEditionByMoneyId.get(i).getMoneyId();
                    GETADDMoneyVersion = ListEditionByMoneyId.get(i).getId();
                    banbie = (ListEditionByMoneyId.get(i).getEditIon());
                } else {

//
                }
            }
            if (null == GETADDMoneyid || GETADDMoneyid.equals("") || banbie.equals("")) {
                handler.sendEmptyMessage(888);
            } else {
                for (ListMoney item : quanbieListxin1) {
                    if (juanbie.equals(item.getMoneytype()) && GETADDMoneyid.equals(item.getMoneyid()) && moneyBanbie.equals(banbie)) {
                        return item;
                    }
                }
            }
        }
        return null;
    }

    /**
     * 是否已经添加过  没添加过为null   添加过 值增加  券得知
     *
     * @param meid
     * @param state
     * @return choose.getMoneyid(), choose.getMoneytype(), juanbie, zhuangtai
     */
    private PKReonciliationEntity chooseExists(String meid, String state) {
//        for (ListMoney item : checklist) {
//            if (meid.equals(item.getMONEYNUM())&&item.getDAMAGEDSTATE().equals(state)) {
//                return item;
//            }
//        }

//        for(int i=0; i<checklist.size(); i++){
//            Log.e(TAG,checklist.get(i).getMONEY());
//            if(checklist.get(i).getDAMAGEDSTATE().equals(zhuangtai)&&
//                    checklist.get(i).getMONEYDETAIL().equals(juanbie)&&
//                    checklist.get(i).getEDITIONNUM().equals(getMoneytype)){}
//
//
//        }
//        for (PKReonciliationEntity item : checklist) {
//            if (item.getDAMAGEDSTATE().equals(zhuangtai)&&
//                    item.getMONEYDETAIL().equals(juanbie)&&
//                    item.getEDITIONNUM().equals(getMoneytype)){
//                ListMoney    listMoney=new ListMoney();
//                listMoney.setMoneytype(item.getMONEYDETAIL());
//                listMoney.setMoneyid(item.getEDITIONNUM());
//                return listMoney;
//            }else{
//
//            }
//
//        }
//
//
//        return null;


        for (PKReonciliationEntity item : checklist) {
            if (meid.equals(item.getMONEYNUM()) && state.equals(item.getDAMAGEDSTATE()) && banbie.equals(item.getEDITIONNUM())) {
                return item;
            }
        }
        return null;
    }

    /***
     * x显示一行   因为  加入scrowview   不能获取高度  所以用当前的新方法
     *
     * @param listView
     */
    public void setListViewHeight(ListView listView) {
        // 获取ListView对应的Adapter
        ListAdapter listAdapter = listView.getAdapter();
        if (listAdapter == null) {
            return;
        }

        int totalHeight = 0;
        for (int i = 0, len = listAdapter.getCount(); i < len; i++) {
            // listAdapter.getCount()返回数据项的数目
            View listItem = listAdapter.getView(i, null, listView);
            // 计算子项View 的宽高
            listItem.measure(0, 0);
            // 统计所有子项的总高度
            totalHeight += listItem.getMeasuredHeight();
        }

        ViewGroup.LayoutParams params = listView.getLayoutParams();
        params.height = totalHeight + (listView.getDividerHeight() * (listAdapter.getCount() - 1));
        // listView.getDividerHeight()获取子项间分隔符占用的高度
        // params.height最后得到整个ListView完整显示需要的高度
        listView.setLayoutParams(params);
    }
}
